package com.ctlele.team.space;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.danikula.videocache.CacheListener;
import com.danikula.videocache.HttpProxyCacheServer;
import com.tencent.rtmp.TXLiveBase;
import com.tencent.rtmp.TXLiveBaseListener;

import java.io.File;

public class MyApplication extends Application {

    private static final String TAG = "MyApplication";

    private HttpProxyCacheServer proxy;

    @Override
    public void onCreate() {
        super.onCreate();
        String licenceURL = "https://license.vod2.myqcloud.com/license/v2/1305488961_1/v_cube.license";
        String licenceKey = "97a625fb21906798b9656da86857e6fb";
        TXLiveBase.getInstance().setLicence(this, licenceURL, licenceKey);
        TXLiveBase.setListener(new TXLiveBaseListener() {
            @Override
            public void onLicenceLoaded(int result, String reason) {
                Log.i(TAG, "onLicenceLoaded: result:" + result + ", reason:" + reason);
            }
        });
    }

    public static HttpProxyCacheServer getProxy(Context context) {
        MyApplication app = (MyApplication) context.getApplicationContext();
        return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
    }

    private HttpProxyCacheServer newProxy() {
        return new HttpProxyCacheServer.Builder(this)
                .maxCacheSize(1024 * 1024 * 1024)
                .build();
    }
}
